<?php
namespace App\Model;

class Order extends Model
{
    // 表名
    protected $table = 'orders';
    
    // 保护属性
    protected $guarded = [];
    
    protected $attributes = [
        'money_count'   => 0,
        'money_remain'  => 0,
        'express'       => '',
        'express_code'  => '',
        'pay'           => '',
        'pay_time'      => '',
        'ok_time'       => '',
        'status'        => self::STATUS_POST,
    ];
    
    // 格式
    protected $casts = [
        'product_image' => 'array',
        'data' => 'array'
    ];

    protected $dateFormat = 'U';
    
    // 状态
    const STATUS_NO      = -1;
    const STATUS_POST    = 0;
    const STATUS_PAY     = 1;
    const STATUS_EXPRESS = 2;
    const STATUS_OK      = 3;
    
    // 用户
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
    
    // 商品
    public function product()
    {
        return $this->belongsTo(Product::class, 'product_id');
    }
    
    // 等级
    public function level()
    {
        return $this->belongsTo(Level::class, 'level_id');
    }
}